#include <algorithm>
#include <cstdio>
typedef long long ll;

const int N = 1000010;
int n, tot = 1, trin[N], trqy[N], tr[N][2], siz[N];
ll k, a[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  scanf("%d%lld", &n, &k);
  trin[1] = trqy[1] = 1;
  int u;
  for (int i = 2; i <= n; ++i) {
    scanf("%d%lld", &u, &a[i]);
    a[i] ^= a[u];
    trin[i] = trqy[i] = 1;
  }
  ll ans = 0;
  for (int i = 62; ~i; --i) {
    ll cnt = 0;
    int tot = 0;
    bool nxt = 0;
    for (int j = 1; j <= n; ++j) {
      tr[j][0] = tr[j][1] = siz[j] = 0;
    }
    for (int j = 1; j <= n; ++j) {
      bool tmp = (a[j] >> i) & 1;
      if (!tr[trin[j]][tmp]) {
        tr[trin[j]][tmp] = ++tot;
      }
      trin[j] = tr[trin[j]][tmp];
      ++siz[trin[j]];
    }
    for (int j = 1; j <= n; ++j) {
      cnt += 0ll + siz[tr[trqy[j]][(a[j] >> i) & 1]];
    }
    if (cnt < k) {
      ans |= 1ll << i;
      nxt = true;
      k -= cnt;
    }
    for (int j = 1; j <= n; ++j) {
      trqy[j] = tr[trqy[j]][nxt ^ ((a[j] >> i) & 1)];
    }
  }
  printf("%lld", ans);
  return 0;
}